//
//  GoodsDetailViewController.m
//  Commerce
//
//  Created by gc on 15/3/28.
//  Copyright (c) 2015年 fei. All rights reserved.
//

#import "GoodsDetailViewController.h"
#import "GoodsBookViewController.h"

@interface GoodsDetailViewController (){
    NSDictionary *_goodsDic;
}

@end

@implementation GoodsDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navStr = @"车辆详情";
    [self getGoodsInfo];
    
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 70, self.navView.frame.size.height-38, 60, 30)];
    [rightBtn setTitle:@"修改" forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"back_n.png"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(gotoModifyGoodsBook) forControlEvents:UIControlEventTouchUpInside];
    [self.navView addSubview:rightBtn];
    // Do any additional setup after loading the view from its nib.
}

- (void)configUI{
    if (_goodsDic[@"StartingCityName"] != [NSNull null]) {
        _startingLabel.text =  _goodsDic[@"StartingCityName"] ;
    }
    if (_goodsDic[@"DestinationCityName"] !=[NSNull null]) {
        _destinationLabel.text = _goodsDic[@"DestinationCityName"];
    }
    _goodsIDLabel.text = [NSString stringWithFormat:@"%@",_goodsDic[@"ScheduleID"]];
    _dateLabel.text = _goodsDic[@"SysTime"];
    _specLabel.text = _goodsDic[@"CarSpecName"];
    _typeLabel.text = _goodsDic[@"CarTypeName"];
    _sendNameLabel.text = [[GlobalData sharedGlobalData] userinfoDic][@"TrueName"];
    _telLabel.text = _goodsDic[@"UserName"];
}

- (void)getGoodsInfo{
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parameters = [GlobalData paramterDic];
    [parameters addEntriesFromDictionary:@{@"Scheduleid":_goodsID}];
    NSLog(@"%@",parameters);
    [[BaseNetwork alloc] initWithMethodUrl:[NSString stringWithFormat:@"%@sch/info",URL_ROOT]
                                    params:parameters
                               requestMode:DGHTTPMethodPOST
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  id responseObject = result;
                                  NSLog(@"responseObject=%@",responseObject);
                                  _goodsDic = responseObject;
                                  [self configUI];
                                  [SVProgressHUD dismiss];
                              }];
}


- (void)gotoModifyGoodsBook{
    GoodsBookViewController *vc = [[GoodsBookViewController alloc] initWithNibName:nil bundle:nil];
    vc.isModify = YES;
    vc.goodsDic = _goodsDic;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
